<?php
include_once 'MySQLDAO.php';

/**
 * Definition of Class Payments
 * This class represents a data access object for the database table 'payments'.
 */
class Payments {


	public $dao = null;

	private $i = 1;

	/**
	 * associated database field: paymentId, type: int, is nullable: false
	 */
	private $paymentId  = 0;

	/**
	 * associated database field: customerId, type: int, is nullable: false
	 */
	private $customerId;

	/**
	 * associated database field: bookingId, type: int, is nullable: false
	 */
	private $bookingId;

	/**
	 * associated database field: paymentMethodId, type: int, is nullable: false
	 */
	private $paymentMethodId;

	/**
	 * associated database field: paymentComments, type: varchar, is nullable: true, character set: utf8, max length: 45
	 */
	private $paymentComments;

	/**
	 * associated database field: paymentAmount, type: float, is nullable: true
	 */
	private $paymentAmount;

	private $customers = null;

	private $bookings = null;

	private $paymentmethods = null;



	/**
	 * Default constructor
	 * @param value some value
	 */
	function __construct(){
		$this->dao = new MySQLDao("Payments");
	}


	/**
	 * Initialize the business object with data read from the DB.
	 * @param row database row array containing the values from one read record
	 */
	public function init($row){
		if(isset($row['paymentId'])) $this->paymentId = $row['paymentId'];
		if(isset($row['customerId'])) $this->customerId = $row['customerId'];
		if(isset($row['bookingId'])) $this->bookingId = $row['bookingId'];
		if(isset($row['paymentMethodId'])) $this->paymentMethodId = $row['paymentMethodId'];
		if(isset($row['paymentComments'])) $this->paymentComments = $row['paymentComments'];
		if(isset($row['paymentAmount'])) $this->paymentAmount = $row['paymentAmount'];
	}


	/**
	 * Returns the string representation for this object
	 * @param escapeQuotationMarks boolean value to indicate if quotation marks in value strings should be escaped, default value is true
	 * @return String String representation of Payments
	 */
	public function toString($escapeQuotationMarks=true){
		$s = '[';
		$s .= 'paymentId: '.(($escapeQuotationMarks===true) ? addslashes($this->paymentId) : $this->paymentId).', ';
		$s .= 'customerId: '.(($escapeQuotationMarks===true) ? addslashes($this->customerId) : $this->customerId).', ';
		$s .= 'bookingId: '.(($escapeQuotationMarks===true) ? addslashes($this->bookingId) : $this->bookingId).', ';
		$s .= 'paymentMethodId: '.(($escapeQuotationMarks===true) ? addslashes($this->paymentMethodId) : $this->paymentMethodId).', ';
		$s .= 'paymentComments: '.(($escapeQuotationMarks===true) ? addslashes($this->paymentComments) : $this->paymentComments).', ';
		$s .= 'paymentAmount: '.(($escapeQuotationMarks===true) ? addslashes($this->paymentAmount) : $this->paymentAmount);
		$s .= ']';
		return $s;
	}


	/**
	 * Returns the JSON (JavaScript Object Notation) string representation for this object
	 * @return String JSON representation of Payments
	 */
	public function toJSONString(){
		$fieldValues = array ("paymentId"=>$this->paymentId, "customerId"=>$this->customerId, "bookingId"=>$this->bookingId, "paymentMethodId"=>$this->paymentMethodId, "paymentComments"=>$this->paymentComments, "paymentAmount"=>$this->paymentAmount);
		return json_encode($fieldValues);
	}


	/**
	 * Returns a HTML representation of this object using DIVs for formatting via css
	 * @param escapeHTML boolean value to indicate if value strings should be html escaped, default value is true
	 * @return String the HTML representation of the Payments object
	 */
	public function toHTMLString($escapeHTML=true){
		$htmlCode = "<div class=\"payments\">\n";
		$htmlCode .= '	<div class="payments_paymentId">'.(($escapeHTML===true) ? htmlspecialchars($this->paymentId) : $this->paymentId)."</div>\n";
		$htmlCode .= '	<div class="payments_customerId">'.(($escapeHTML===true) ? htmlspecialchars($this->customerId) : $this->customerId)."</div>\n";
		$htmlCode .= '	<div class="payments_bookingId">'.(($escapeHTML===true) ? htmlspecialchars($this->bookingId) : $this->bookingId)."</div>\n";
		$htmlCode .= '	<div class="payments_paymentMethodId">'.(($escapeHTML===true) ? htmlspecialchars($this->paymentMethodId) : $this->paymentMethodId)."</div>\n";
		$htmlCode .= '	<div class="payments_paymentComments">'.(($escapeHTML===true) ? htmlspecialchars($this->paymentComments) : $this->paymentComments)."</div>\n";
		$htmlCode .= '	<div class="payments_paymentAmount">'.(($escapeHTML===true) ? htmlspecialchars($this->paymentAmount) : $this->paymentAmount)."</div>\n";
		$htmlCode .= "</div>\n";
		return $htmlCode;
	}
	/*
	public function getData($where) {
		$rows = $this->dao->getData($where);
		return $rows;
	}*/
	
	public static function deleteRecords($where) {
		$payments = new Payments();
		$payments->dao->deleteRecord ($where);
		return;
	}


	public static function loadAll(){
		$payments = new Payments();
		$rows = $payments->dao->getData("");
		$paymentss = array();
		for ($index = 0; $index < sizeof($rows); $index++) {
			$d = new Payments();
			$d->init($rows[$index]);
			array_push($paymentss,$d);
		}
		return $paymentss;
	}


	/**
	 * Load the Payments uniquely by its primary key.
	 * @param paymentId the primary key
	 * @return Payments Instance of {@link Payments}
	 */
	public static function loadUnique($paymentId){
		$payments = new Payments();
		$rows = $payments->dao->getData("`paymentId`='$paymentId'");
		$payments->init($rows[0]);
		return $payments;
	}


	/**
	 * Load all records of Payments uniquely by its foreign keys:
	 * paymentMethodId
	 * @param paymentMethodId foreign key
	 * @return array of Instance of {@link Payments}
	 */
	public static function loadByFKPaymentmethodid($paymentMethodId){
		$payments = new Payments();
		$rows = $payments->dao->getData("`paymentMethodId`='$paymentMethodId'");
		$paymentss = array();
		for ($index = 0; $index < sizeof($rows); $index++) {
			$d = new Payments();
			$d->init($rows[$index]);
			array_push($paymentss,$d);
		}
		return $paymentss;
	}


	/**
	 * Load all records of Payments uniquely by its foreign keys:
	 * customerId
	 * @param customerId foreign key
	 * @return array of Instance of {@link Payments}
	 */
	public static function loadByFKCustomerid($customerId){
		$payments = new Payments();
		$rows = $payments->dao->getData("`customerId`='$customerId'");
		$paymentss = array();
		for ($index = 0; $index < sizeof($rows); $index++) {
			$d = new Payments();
			$d->init($rows[$index]);
			array_push($paymentss,$d);
		}
		return $paymentss;
	}


	/**
	 * Load all records of Payments uniquely by its foreign keys:
	 * bookingId
	 * @param bookingId foreign key
	 * @return array of Instance of {@link Payments}
	 */
	public static function loadByFKBookingid($bookingId){
		$payments = new Payments();
		$rows = $payments->dao->getData("`bookingId`='$bookingId'");
		$paymentss = array();
		for ($index = 0; $index < sizeof($rows); $index++) {
			$d = new Payments();
			$d->init($rows[$index]);
			array_push($paymentss,$d);
		}
		return $paymentss;
	}


	/**
	 * Insert this object into the DB
	 * @return number new id (auto increment value) genereated
	 */
	public function insert(){
		//$list = array("paymentId"=>$this->paymentId, "customerId"=>$this->customerId, "bookingId"=>$this->bookingId, "paymentMethodId"=>$this->paymentMethodId, "paymentComments"=>$this->paymentComments, "paymentAmount"=>$this->paymentAmount);
		$list = array("customerId"=>$this->customerId, "bookingId"=>$this->bookingId, "paymentMethodId"=>$this->paymentMethodId, "paymentComments"=>$this->paymentComments, "paymentAmount"=>$this->paymentAmount);
		return $this->dao->insertRecord($list);
	}


	/**
	 * Update this object into the DB
	 * @return number the number of updated records
	 */
	public function update(){
		//$list = array("paymentId"=>$this->paymentId, "customerId"=>$this->customerId, "bookingId"=>$this->bookingId, "paymentMethodId"=>$this->paymentMethodId, "paymentComments"=>$this->paymentComments, "paymentAmount"=>$this->paymentAmount);
		$list = array("customerId"=>$this->customerId, "bookingId"=>$this->bookingId, "paymentMethodId"=>$this->paymentMethodId, "paymentComments"=>$this->paymentComments, "paymentAmount"=>$this->paymentAmount);
		$where = "`paymentId`='$paymentId'";
		return $this->dao->updateRecord($list,$where);
	}


	/**
	 * Initialize the business object with data read from the DB.
	 */
	public function initPOST(){
		if (isset($_POST['paymentId'])){
			$this->paymentId = $_POST['paymentId'];
		}
		if (isset($_POST['customerId'])){
			$this->customerId = $_POST['customerId'];
		}
		if (isset($_POST['bookingId'])){
			$this->bookingId = $_POST['bookingId'];
		}
		if (isset($_POST['paymentMethodId'])){
			$this->paymentMethodId = $_POST['paymentMethodId'];
		}
		if (isset($_POST['paymentComments'])){
			$this->paymentComments = $_POST['paymentComments'];
		}
		if (isset($_POST['paymentAmount'])){
			$this->paymentAmount = $_POST['paymentAmount'];
		}
	}


	/**
	 * Initialize the business object with data read from the DB.
	 */
	public function initGET(){
		if (isset($_GET['paymentId'])){
			$this->paymentId = $_GET['paymentId'];
		}
		if (isset($_GET['customerId'])){
			$this->customerId = $_GET['customerId'];
		}
		if (isset($_GET['bookingId'])){
			$this->bookingId = $_GET['bookingId'];
		}
		if (isset($_GET['paymentMethodId'])){
			$this->paymentMethodId = $_GET['paymentMethodId'];
		}
		if (isset($_GET['paymentComments'])){
			$this->paymentComments = $_GET['paymentComments'];
		}
		if (isset($_GET['paymentAmount'])){
			$this->paymentAmount = $_GET['paymentAmount'];
		}
	}


	/**
	 * Returns the value from the database field paymentId.
	 * In the database the field paymentId is of type int.
	 * The database field is NOT nullable.
	 * @return String the value of the field
	 */
	public function getPaymentId(){
		return $this->paymentId;
	}


	/**
	 * Set the value from the database field paymentId.
	 * In the database the field paymentId is of type int.
	 * The database field is NOT nullable.
	 * @param paymentId String with the value for the field to be set
	 */
	public function setPaymentId($paymentId){
		$this->paymentId = $paymentId;
	}


	/**
	 * Returns the value from the database field customerId.
	 * In the database the field customerId is of type int.
	 * The database field is NOT nullable.
	 * @return String the value of the field
	 */
	public function getCustomerId(){
		return $this->customerId;
	}


	/**
	 * Set the value from the database field customerId.
	 * In the database the field customerId is of type int.
	 * The database field is NOT nullable.
	 * @param customerId String with the value for the field to be set
	 */
	public function setCustomerId($customerId){
		$this->customerId = $customerId;
	}


	/**
	 * Returns the value from the database field bookingId.
	 * In the database the field bookingId is of type int.
	 * The database field is NOT nullable.
	 * @return String the value of the field
	 */
	public function getBookingId(){
		return $this->bookingId;
	}


	/**
	 * Set the value from the database field bookingId.
	 * In the database the field bookingId is of type int.
	 * The database field is NOT nullable.
	 * @param bookingId String with the value for the field to be set
	 */
	public function setBookingId($bookingId){
		$this->bookingId = $bookingId;
	}


	/**
	 * Returns the value from the database field paymentMethodId.
	 * In the database the field paymentMethodId is of type int.
	 * The database field is NOT nullable.
	 * @return String the value of the field
	 */
	public function getPaymentMethodId(){
		return $this->paymentMethodId;
	}


	/**
	 * Set the value from the database field paymentMethodId.
	 * In the database the field paymentMethodId is of type int.
	 * The database field is NOT nullable.
	 * @param paymentMethodId String with the value for the field to be set
	 */
	public function setPaymentMethodId($paymentMethodId){
		$this->paymentMethodId = $paymentMethodId;
	}


	/**
	 * Returns the value from the database field paymentComments.
	 * In the database the field paymentComments is of type varchar.
	 * The database field is  nullable.
	 * @return String the value of the field
	 */
	public function getPaymentComments(){
		return $this->paymentComments;
	}


	/**
	 * Set the value from the database field paymentComments.
	 * In the database the field paymentComments is of type varchar.
	 * The database field is  nullable.
	 * @param paymentComments String with the value for the field to be set
	 */
	public function setPaymentComments($paymentComments){
		if(strlen($paymentComments) > 45) throw new Exception("paymentComments does not allow strings longer than 45 characters. The submitted string contains ".strlen($paymentComments)." characters.");
		$this->paymentComments = $paymentComments;
	}


	/**
	 * Returns the value from the database field paymentAmount.
	 * In the database the field paymentAmount is of type float.
	 * The database field is  nullable.
	 * @return String the value of the field
	 */
	public function getPaymentAmount(){
		return $this->paymentAmount;
	}


	/**
	 * Set the value from the database field paymentAmount.
	 * In the database the field paymentAmount is of type float.
	 * The database field is  nullable.
	 * @param paymentAmount String with the value for the field to be set
	 */
	public function setPaymentAmount($paymentAmount){
		$this->paymentAmount = $paymentAmount;
	}


	/**
	 * Returns an instance of the linked Customers object.
	 * A One to Many (1:n) relation exists between the Payments and the Customers table.
	 * @return Customers the linked instance of Customers
	 */
	public function getCustomers(){
		if($this->customers == null){
			$this->customers = Customers::loadUnique($this->customerId);
		}
		return $this->customers;
	}


	/**
	 * Set a link to a related Customers instance
	 * @param targetObjectInstanceName instance of Customers to be linked to this object instance
	 */
	public function setCustomers($customers){
		$customers->customerId = $this->customerId;
		$this->customers = $customers;
	}


	/**
	 * Returns an instance of the linked Bookings object.
	 * A One to Many (1:n) relation exists between the Payments and the Bookings table.
	 * @return Bookings the linked instance of Bookings
	 */
	public function getBookings(){
		if($this->bookings == null){
			$this->bookings = Bookings::loadUnique($this->bookingId);
		}
		return $this->bookings;
	}


	/**
	 * Set a link to a related Bookings instance
	 * @param targetObjectInstanceName instance of Bookings to be linked to this object instance
	 */
	public function setBookings($bookings){
		$bookings->bookingId = $this->bookingId;
		$this->bookings = $bookings;
	}


	/**
	 * Returns an instance of the linked Paymentmethods object.
	 * A One to Many (1:n) relation exists between the Payments and the Paymentmethods table.
	 * @return Paymentmethods the linked instance of Paymentmethods
	 */
	public function getPaymentmethods(){
		if($this->paymentmethods == null){
			$this->paymentmethods = Paymentmethods::loadUnique($this->paymentMethodId);
		}
		return $this->paymentmethods;
	}


	/**
	 * Set a link to a related Paymentmethods instance
	 * @param targetObjectInstanceName instance of Paymentmethods to be linked to this object instance
	 */
	public function setPaymentmethods($paymentmethods){
		$paymentmethods->paymentMethodId = $this->paymentMethodId;
		$this->paymentmethods = $paymentmethods;
	}
}
?>